package cn.net.autocode.files;

import com.alibaba.fastjson2.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class FileTools {

    public static JSONObject parase(File file){
        try {
            InputStream inputStream = new FileInputStream(file);
            FileParse fileParse = new FileParse();
            return fileParse.handleStream(inputStream);
        } catch (Exception e) {
            JSONObject rs = new JSONObject();
            rs.put("code",0);
            rs.put("msg",e.getMessage());
            return rs;
        }
    }

    public static JSONObject parase(InputStream inputStream){
        try {
            FileParse fileParse = new FileParse();
            return fileParse.handleStream(inputStream);
        } catch (Exception e) {
            JSONObject rs = new JSONObject();
            rs.put("code",0);
            rs.put("msg",e.getMessage());
            return rs;
        }
    }

    public static void main(String[] args){
        File file = new File("D:/1124032801   PB-75_1.TXT");
        JSONObject json = FileTools.parase(file);
        String html = json.getString("htmlContent");
        String xml = json.getString("xmlContent");
        String text = json.getString("textContent");

        if(html.equals(xml)){
            System.out.println("文件内容相同");
        }else{
            System.out.println("文件内容不同");
        }

    }


}
